#ifndef UIDEVICECOMMPAREDID_H
#define UIDEVICECOMMPAREDID_H

#include <QWidget>
#include <QComboBox>
#include <QLineEdit>
#include <QPushButton>
#include <QFormLayout>

class SerialPortSettingsWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SerialPortSettingsWidget(QWidget *parent = nullptr): QWidget(parent)
    {
        initControls();
        populateData();
    }

    void initControls()
    {
        // 创建控件
        portNameComboBox = new QComboBox(this);
        baudRateComboBox = new QComboBox(this);
        dataBitsComboBox = new QComboBox(this);
        parityComboBox = new QComboBox(this);
        stopBitsComboBox = new QComboBox(this);
        flowControlComboBox = new QComboBox(this);
        applyButton = new QPushButton("Apply", this);

        // 设置布局
        QFormLayout *layout = new QFormLayout(this);
        layout->addRow("Port Name:", portNameComboBox);
        layout->addRow("Baud Rate:", baudRateComboBox);
        layout->addRow("Data Bits:", dataBitsComboBox);
        layout->addRow("Parity:", parityComboBox);
        layout->addRow("Stop Bits:", stopBitsComboBox);
        layout->addRow("Flow Control:", flowControlComboBox);
        layout->addRow(applyButton);

        // 设置控件属性
        portNameComboBox->setEditable(false);
        baudRateComboBox->setEditable(true);
        dataBitsComboBox->setEditable(false);
        parityComboBox->setEditable(false);
        stopBitsComboBox->setEditable(false);
        flowControlComboBox->setEditable(false);

        // 设置布局边距和间距
        layout->setSpacing(10);

        // 设置窗体大小
        setFixedSize(400, 300);
    }

    void populateData() {
        // 填充串口名称
        // QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
        // for (const QSerialPortInfo &port : ports) {
        //     portNameComboBox->addItem(port.portName());
        // }

        // // 填充波特率
        // baudRateComboBox->addItem("1200", QSerialPort::Baud1200);
        // baudRateComboBox->addItem("2400", QSerialPort::Baud2400);
        // baudRateComboBox->addItem("4800", QSerialPort::Baud4800);
        // baudRateComboBox->addItem("9600", QSerialPort::Baud9600);
        // baudRateComboBox->addItem("19200", QSerialPort::Baud19200);
        // baudRateComboBox->addItem("38400", QSerialPort::Baud38400);
        // baudRateComboBox->addItem("57600", QSerialPort::Baud57600);
        // baudRateComboBox->addItem("115200", QSerialPort::Baud115200);

        // // 填充数据位
        // dataBitsComboBox->addItem("5", QSerialPort::Data5);
        // dataBitsComboBox->addItem("6", QSerialPort::Data6);
        // dataBitsComboBox->addItem("7", QSerialPort::Data7);
        // dataBitsComboBox->addItem("8", QSerialPort::Data8);

        // // 填充校验位
        // parityComboBox->addItem("None", QSerialPort::NoParity);
        // parityComboBox->addItem("Even", QSerialPort::EvenParity);
        // parityComboBox->addItem("Odd", QSerialPort::OddParity);
        // parityComboBox->addItem("Space", QSerialPort::SpaceParity);
        // parityComboBox->addItem("Mark", QSerialPort::MarkParity);

        // // 填充停止位
        // stopBitsComboBox->addItem("1", QSerialPort::OneStop);
        // stopBitsComboBox->addItem("1.5", QSerialPort::OneAndHalfStop);
        // stopBitsComboBox->addItem("2", QSerialPort::TwoStop);

        // // 填充流控制
        // flowControlComboBox->addItem("None", QSerialPort::NoFlowControl);
        // flowControlComboBox->addItem("Hardware", QSerialPort::HardwareControl);
        // flowControlComboBox->addItem("Software", QSerialPort::SoftwareControl);
    }

private:
    QComboBox *portNameComboBox;
    QComboBox *baudRateComboBox;
    QComboBox *dataBitsComboBox;
    QComboBox *parityComboBox;
    QComboBox *stopBitsComboBox;
    QComboBox *flowControlComboBox;
    QPushButton *applyButton;
};

class UiDeviceCommParEdid : public QWidget
{
    Q_OBJECT
public:
    explicit UiDeviceCommParEdid(QWidget *parent = nullptr);

signals:
};

#endif // UIDEVICECOMMPAREDID_H
